package hn.cch.framework.database;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class PostgreSQLDemo {

    private static final Logger logger = LoggerFactory.getLogger(PostgreSQLDemo.class);

    public static void main(String[] args) throws ClassNotFoundException {

        String className = "org.postgresql.Driver";
        String url = "jdbc:postgresql://localhost:5432/postgres";
        String user = "chench";
        String password = "chench";
        String sql = "select * from t_login";


        Class.forName(className);
        try (Connection connection = DriverManager.getConnection(url, user, password);
             Statement statement = connection.createStatement()) {
            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                logger.info(resultSet.getString("username") + "|" + resultSet.getString("password"));
            }
            resultSet.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
